#include "Create_Model.h"

Create_Model::Create_Model()
{

}
void Create_Model::C_Model(HObject Img,HTuple WindowHandle,HTuple SavePath)
{
    HTuple Row1, Column1, Row2, Column2;
    HObject Rectangle,ImageReduced,ModelContours,ContoursAffineTrans;
    HTuple ModelID,Row, Column, Angle, Score,HomMat2D;
    try
    {
        SetColor(WindowHandle,"red");
        DrawRectangle1(WindowHandle, &Row1, &Column1, &Row2, &Column2);
        GenRectangle1(&Rectangle, Row1, Column1, Row2, Column2);
        ReduceDomain(Img, Rectangle, &ImageReduced);
        CreateShapeModel (ImageReduced, "auto", -0.39, 0.79, "auto", "auto", "use_polarity", "auto", "auto", &ModelID);
        GetShapeModelContours (&ModelContours, ModelID, 1);
        FindShapeModel (ImageReduced, ModelID, -0.39, 0.79, 0.5, 1, 0.5, "least_squares", 0, 0.9, &Row, &Column, &Angle, &Score);
        VectorAngleToRigid (0, 0, 0, Row, Column, Angle, &HomMat2D);
        AffineTransContourXld (ModelContours, &ContoursAffineTrans, HomMat2D);
        DispObj(ContoursAffineTrans, WindowHandle);
    //    path='C:/Users/59514/Desktop/123'
        WriteShapeModel (ModelID, SavePath);
    }
    catch(HException ex)
    {

    }

}
